from collections import namedtuple
import numpy

#GLOBALS
landuse = ['COM', 'IND', 'POS', 'RES', 'VAC', 'TRL', 'TRM', 'TRH', 'TRU', 'WAT']
landuseLongName = ['Commercial', 'Industrial', 'Parks and Open Space', 'Residential', 'Vacant Land',
                    'Low-Traffic Street', 'Medium-Traffic Street', 'High-Traffic Street', 'Unimproved Street', 'Surface Water']

pollutantList = ['TSS','TP','PbD','BOD','ecoli']
pollutantLoadUnits= {'TSS':'lbs',
                    'TP':'lbs',
                    'PbD':'lbs',
                    'BOD':'lbs',
                    'ecoli':'cfu'}
pollutantConcentrationUnits= {'TSS':'mg_per_L',
                    'TP':'mg_per_L',
                    'PbD':'ug_per_L',
                    'BOD':'mg_per_L',
                    'ecoli':'cfu_per_100_mL'}

annualRainfallDepth = 36.5

mg_per_L_conversion = 5.202e-6
ug_per_L_conversion = 5.202e-9
cfu_per_100_mL_conversion = 23.597

LanduseConcentrationT = namedtuple('LanduseConcentrationT', 'landuse mean lci uci units')

def LanduseConcentration(lu, mean, lci, uci, units='mg/L'):
    return LanduseConcentrationT(lu, mean, lci, uci, units)

BmpT = namedtuple('BmpT', 'bmp mean lci uci units')

def Bmp(bmp, mean, lci, uci, units='mg/l'):
    return BmpT(bmp, mean, lci, uci, units)


scores = numpy.array([1, 2, 3, 4, 5])

tssScoreBasis = numpy.array([2, 20, 50, 100, 184])
pbScoreBasis = numpy.array([0.1, 0.4, 1.2, 5, 31.5])
tpScoreBasis = numpy.array([0.02, 0.05, 0.13, 0.25, 0.51])
bodScoreBasis = numpy.array([1, 2, 3, 10, 39.6])
ecoliScoreBasis = numpy.array([10, 126, 406, 1000, 1656])

tssLuConcentration = {'COM':LanduseConcentration(lu='COM', mean=90, lci=64, uci=103),
                    'IND':LanduseConcentration(lu='IND', mean=150, lci=117, uci=284),
                    'POS':LanduseConcentration(lu='POS', mean=25, lci=16, uci=50),
                    'RES':LanduseConcentration(lu='RES', mean=60, lci=44, uci=99),
                    'VAC':LanduseConcentration(lu='VAC', mean=25, lci=16, uci=50),
                    'TRL':LanduseConcentration(lu='TRL', mean=60, lci=44, uci=99), #'RES' values for now
                    'TRM':LanduseConcentration(lu='TRM', mean=90, lci=64, uci=103), #'COM' values for now
                    'TRH':LanduseConcentration(lu='TRH', mean=90, lci=64, uci=103), #Old 'TRA' values
                    'TRU':LanduseConcentration(lu='TRU', mean=600, lci=440, uci=990), #'RES' values for now, but TSS increased 10x
                    #'WAT':LanduseConcentration(lu='WAT', mean=0, lci=0, uci=0)
                    }

pbLuConcentration = {'COM':LanduseConcentration(lu='COM', mean=4.97, lci=3.2, uci=7.38, units='ug/l'),
                    'IND':LanduseConcentration(lu='IND', mean=2.58, lci=1.52, uci=3.77, units='ug/l'),
                    'POS':LanduseConcentration(lu='POS', mean=0.118, lci=0.109, uci=0.128, units='ug/l'),
                    'RES':LanduseConcentration(lu='RES', mean=1.80, lci=1.23, uci=2.53, units='ug/l'),
                    'VAC':LanduseConcentration(lu='VAC', mean=0.118, lci=0.109, uci=0.128, units='ug/l'),
                    'TRL':LanduseConcentration(lu='TRL', mean=1.80, lci=1.23, uci=2.53, units='ug/l'), #'RES' values for now
                    'TRM':LanduseConcentration(lu='TRM', mean=4.97, lci=3.2, uci=7.38, units='ug/l'), #'COM' values for now
                    'TRH':LanduseConcentration(lu='TRH', mean=3.59, lci=1.26, uci=7.71, units='ug/l'), #Old 'TRA' values
                    'TRU':LanduseConcentration(lu='TRU', mean=1.80, lci=1.23, uci=2.53, units='ug/l'), #'RES' values for now
                    #'WAT':LanduseConcentration(lu='WAT', mean=0, lci=0, uci=0, units='ug/l')
                   }

#TP values are Median, not Mean
tpLuConcentration = {'COM':LanduseConcentration(lu='COM', mean=0.28, lci=0.23, uci=0.31),
                    'IND':LanduseConcentration(lu='IND', mean=0.47, lci=0.36, uci=0.65),
                    'POS':LanduseConcentration(lu='POS', mean=0.086, lci=0.079, uci=0.089),
                    'RES':LanduseConcentration(lu='RES', mean=0.21, lci=0.16, uci=0.23),
                    'VAC':LanduseConcentration(lu='VAC',mean=0.086, lci=0.079, uci=0.089),
                    'TRL':LanduseConcentration(lu='TRL', mean=0.21, lci=0.16, uci=0.23), #'RES' values for now
                    'TRM':LanduseConcentration(lu='TRM',  mean=0.28, lci=0.23, uci=0.31), #'COM' values for now
                    'TRH':LanduseConcentration(lu='TRH', mean=0.31, lci=0.24, uci=0.41), #Old 'TRA' values
                    'TRU':LanduseConcentration(lu='TRU', mean=0.21, lci=0.16, uci=0.23), #'RES' values for now
                    #'WAT':LanduseConcentration(lu='WAT',mean=0, lci=0, uci=0)
                   }

bodLuConcentration = {'COM':LanduseConcentration(lu='COM', mean=11.9, lci=8.5, uci=16.6),
                    'IND':LanduseConcentration(lu='IND', mean=39.6, lci=26.1, uci=56.1),
                    'POS':LanduseConcentration(lu='POS', mean=2.0, lci=2.0, uci=2.0),
                    'RES':LanduseConcentration(lu='RES', mean=8.1, lci=5.9, uci=10.8),
                    'VAC':LanduseConcentration(lu='VAC',mean=2.0, lci=2.0, uci=2.0),
                    'TRL':LanduseConcentration(lu='TRL', mean=8.1, lci=5.9, uci=10.8), #'RES' values for now
                    'TRM':LanduseConcentration(lu='TRM', mean=11.9, lci=8.5, uci=16.6), #'COM' values for now
                    'TRH':LanduseConcentration(lu='TRH', mean=17.9, lci=10.0, uci=29.1), #Old 'TRA' values
                    'TRU':LanduseConcentration(lu='TRU', mean=8.1, lci=5.9, uci=10.8), #'RES' values for now
                    #'WAT':LanduseConcentration(lu='WAT',mean=0, lci=0, uci=0)
                    }

ecoliLuConcentration = {'COM':LanduseConcentration(lu='COM', mean=1247, lci=573, uci=2409, units='CFU / 100 ml'),
                    'IND':LanduseConcentration(lu='IND', mean=438, lci=154, uci=1004, units='CFU / 100 ml'),
                    'POS':LanduseConcentration(lu='POS', mean=87, lci=57, uci=124, units='CFU / 100 ml'),
                    'RES':LanduseConcentration(lu='RES', mean=1656, lci=970, uci=2651, units='CFU / 100 ml'),
                    'VAC':LanduseConcentration(lu='VAC', mean=87, lci=57, uci=124, units='CFU / 100 ml'),
                    'TRL':LanduseConcentration(lu='TRL', mean=1656, lci=970, uci=2651, units='CFU / 100 ml'), #'RES' values for now
                    'TRM':LanduseConcentration(lu='TRM', mean=1247, lci=573, uci=2409, units='CFU / 100 ml'), #'COM' values for now
                    'TRH':LanduseConcentration(lu='TRH', mean=1507, lci=686, uci=2962, units='CFU / 100 ml'), #Old 'TRA' values
                    'TRU':LanduseConcentration(lu='TRU', mean=1656, lci=970, uci=2651, units='CFU / 100 ml'), #'RES' values for now
                    #'WAT':LanduseConcentration(lu='WAT',mean=0, lci=0, uci=0, units='CFU / 100 ml')
                      }

bmps = ('#Centrifugal Separator','Filters','Dry Vegetated Detention Pond',
        'Wet Retention Basin', 'Swales', 'Wetlands', 'Sediment Manhole',
        'Green Roofs', '#Porous Pavement','#Infiltration Facility',
        'Minimally Effective Facility',	'Lined Planter')

tssReduction = (#Bmp(bmp='#Centrifugal Separator', mean=115, lci=85, uci=145),
                Bmp(bmp='Filter', mean=42, lci=32.9, uci=52.7),
                Bmp(bmp='Dry Detention Pond', mean=44.4, lci=34.9, uci=55), #Dry Vegetated Detention Pond
                Bmp(bmp='Wet Retention Basin', mean=41, lci=27, uci=56), #Wet Retention Basin
                Bmp(bmp='Swales', mean=23.6, lci=18.9, uci=28.5),
                Bmp(bmp='Wetlands', mean=24.7, lci=17.3, uci=34.3),
                Bmp(bmp='Sedimentation Manhole', mean=66, lci=45, uci=90),
                Bmp(bmp='Green Roofs', mean=5.4, lci=3.1, uci=8.1),
                #Bmp(bmp='#Porous Pavement', mean=0, lci=0, uci=0),
                #Bmp(bmp='#Infiltration Facility', mean=0, lci=0, uci=0),
                #Bmp(bmp='Minimally Effective Facility', mean=115, lci=85, uci=145),
                Bmp(bmp='Lined Planter', mean=42, lci=32.9, uci=52.7))

pbReduction = (#Bmp(bmp='#Centrifugal Separator', mean=13.3, lci=9.4 uci=17.6),
                Bmp(bmp='Filter', mean=8, lci=6.1, uci=10.2),
                Bmp(bmp='Dry Detention Pond', mean=32.8, lci=24.4, uci=43.0), #Dry Vegetated Detention Pond
                Bmp(bmp='Wet Retention Basin', mean=2.4, lci=1.7, uci=3.2), #Wet Retention Basin
                Bmp(bmp='Swales', mean=7.2, lci=5.6, uci=8.8),
                Bmp(bmp='Wetlands', mean=2.4, lci=1.7, uci=3.2),
                Bmp(bmp='Sedimentation Manhole', mean=9.1, lci=6.2, uci=12.3),
                Bmp(bmp='Green Roofs', mean=1.05, lci=0.52, uci=1.85),
                #Bmp(bmp='#Porous Pavement', mean=0, lci=0, uci=0),
                #Bmp(bmp='#Infiltration Facility', mean=0, lci=0, uci=0),
                #Bmp(bmp='Minimally Effective Facility', mean=115, lci=85, uci=145),
                Bmp(bmp='Lined Planter', mean=8.0, lci=6.1, uci=10.2)
                )

#Values are Median, not Mean
tpReduction = (Bmp(bmp='Centrifugal Separator', mean=0.14, lci=0.10, uci=0.17),
                Bmp(bmp='Filters', mean=0.12, lci=0.10, uci=0.22),
                Bmp(bmp='Dry Detention Pond', mean=0.29, lci=0.24, uci=0.33), #Dry Vegetated Detention Pond
                Bmp(bmp='Wet Retention Basin', mean=0.14, lci=0.12, uci=0.17), #Wet Retention Basin
                Bmp(bmp='Swales', mean=0.22, lci=0.20, uci=0.23),
                Bmp(bmp='Wetlands', mean=0.08, lci=0.06, uci=0.09),
                Bmp(bmp='Sedimentation Manhole', mean=0.14, lci=0.10, uci=0.17),
                Bmp(bmp='Green Roofs', mean=0.35, lci=0.28, uci=0.45),
                #Bmp(bmp='#Porous Pavement', mean=0, lci=0, uci=0),
                #Bmp(bmp='#Infiltration Facility', mean=0, lci=0, uci=0),
                #Bmp(bmp='Minimally Effective Facility', mean=0.29, lci=0.24, uci=0.33),
                #Bmp(bmp='Lined Planter', mean=0.29, lci=0.24, uci=0.33)
                )

bodReduction = (Bmp(bmp='Centrifugal Separator', mean=6.0, lci=3.6, uci=7.6),
                Bmp(bmp='Filters', mean=3.4, lci=2.2, uci=4.8),
                Bmp(bmp='Dry Detention Pond', mean=12.2, lci=8.6, uci=16.8), #Dry Vegetated Detention Pond
                Bmp(bmp='Wet Retention Basin', mean=6.1, lci=4.3, uci=8.8), #Wet Retention Basin
                Bmp(bmp='Swales', mean=5.4, lci=4.0, uci=6.9),
                Bmp(bmp='Wetlands', mean=6.1, lci=4.3, uci=8.4),
                Bmp(bmp='Sedimentation Manhole', mean=6.0, lci=3.6, uci=7.6),
                Bmp(bmp='Green Roofs', mean=2.4, lci=2.0, uci=3.0),
                #Bmp(bmp='#Porous Pavement', mean=0, lci=0, uci=0),
                #Bmp(bmp='#Infiltration Facility', mean=0, lci=0, uci=0),
                #Bmp(bmp='Minimally Effective Facility', mean=12.2, lci=8.6, uci=16.8),
                Bmp(bmp='Lined Planter', mean=3.4, lci=2.2, uci=4.8)
                )

ecoliReduction = (Bmp(bmp='Centrifugal Separator', mean=5587, lci=594, uci=22454),
                Bmp(bmp='Filters', mean=91, lci=28, uci=184),
                Bmp(bmp='Dry Detention Pond', mean=1922, lci=916, uci=3584), #Dry Vegetated Detention Pond
                Bmp(bmp='Wet Retention Basin', mean=499, lci=146, uci=1220), #Wet Retention Basin
                Bmp(bmp='Swales', mean=1922, lci=916, uci=3584),
                Bmp(bmp='Wetlands', mean=499, lci=146, uci=1220),
                Bmp(bmp='Sedimentation Manhole', mean=5587, lci=594, uci=22454),
                Bmp(bmp='Green Roofs', mean=20, lci=10, uci=38),
                #Bmp(bmp='#Porous Pavement', mean=0, lci=0, uci=0),
                #Bmp(bmp='#Infiltration Facility', mean=0, lci=0, uci=0),
                #Bmp(bmp='Minimally Effective Facility', mean=5587, lci=916, uci=22454),
                Bmp(bmp='Lined Planter', mean=91, lci=28, uci=184)
                )